package org.springcloud.wisdom.springcloud_03_freshman.student.service;


import org.springcloud.wisdom.springcloud_03_freshman.student.dao.CardDao;
import org.springcloud.wisdom.springcloud_03_freshman.student.entity.Card;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.yaml.snakeyaml.events.Event;

@Service
public class CardService {

    @Autowired
    CardDao cardDao;

    public boolean insert(Card card){
        if (card.getSid() == null || card.getSid().trim().length() <9 || card.getSid().trim().length()>9){
            return false;
        }
        if (card.getUser().trim().length() ==0 || card.getLocation().trim().length() ==0 ){
            return false;
        }
        return cardDao.addCard(card)>0;
    }

    public boolean update(Card card){
        if (card.getSid() == null || card.getSid().trim().length() <9 || card.getSid().trim().length()>9){
            return false;
        }
        if ( card.getLocation().trim().length() ==0 ){
            return false;
        }
        return cardDao.updateCard(card)>0;
    }

    public Card get(String sid){
        if (sid == null || sid.trim().length()>9 ||sid.trim().length()<9){
            return null;
        }
        return cardDao.getCardBySid(sid);
    }
}
